package com.dragon.modules.yuegou.service.impl.merchant;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.common.web.PageRequest;
import com.dragon.modules.yuegou.entity.merchant.ActivityFaqEntity;
import com.dragon.modules.yuegou.mapper.merchant.ActivityFaqMapper;
import com.dragon.modules.yuegou.model.merchant.ActivityFaq;
import com.dragon.modules.yuegou.query.merchant.ActivityFaqQuery;
import com.dragon.modules.yuegou.service.merchant.ActivityFaqService;
import com.dragon.modules.yuegou.utils.PageToResultUtils;
import com.dragon.modules.yuegou.web.Check;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 咨询 服务实现
 *
 * @author pbuilder generated
 * @date 2019-09-23 10:25:45
 * @version 2.0
 */
@Service("merActivityFaqService")
public class ActivityFaqServiceImpl
		extends ServiceImpl<ActivityFaqMapper, ActivityFaqEntity>
		implements ActivityFaqService {
	
	@Override
	public IPage<ActivityFaq> search(PageRequest page, ActivityFaqQuery query) {
		return baseMapper.search(PageToResultUtils.resultToPage(page),query);
	}

	@Override
	public ActivityFaq getFaq(String id) {
		if (StringUtils.isEmpty(id)){
			return new ActivityFaq();
		}
		ActivityFaqEntity entity = getById(id);
		return new ActivityFaq(entity);
	}

	@Override
	public void saveFaq(ActivityFaq activityFaq) {
		Check.notEmpty(activityFaq.getTitle(),"标题不能为空");
		Check.notEmpty(activityFaq.getColumnId(),"栏目Id不能为空");
		Check.notEmpty(activityFaq.getContent(),"内容不能为空");
		save(activityFaq);
	}

	@Override
	public void saveSortNo(String id, Integer sortNo) {
		Check.notEmpty(id,"问题Id不能为空");
		Check.digits(sortNo,5,0,"问题排序必须是正整数");
		Check.positive(sortNo,"问题排序必须是正数");
		
		ActivityFaq activityFaq = new ActivityFaq();
		activityFaq.setSortNo(sortNo);
		
		ActivityFaqQuery query = new ActivityFaqQuery();
		query.setId(id);
		update(activityFaq, query.toQueryWrapper());
	}

	@Override
	public void deleteFaq(String id) {
		Check.notEmpty(id,"问题Id不能为空");
		removeById(id);
	}

}